package jnBase.view
{
	import jnBase.Api;
	import jnBase.Data;
	import jnBase.PSteps;
	
	import laya.events.Event;
	import laya.ui.Box;
	import laya.ui.Button;
	import laya.utils.Browser;
	import laya.utils.Ease;
	import laya.utils.Handler;
	import laya.utils.Tween;
	
	import ui.tools.UserNavUI;
	
	public class UserNav extends UserNavUI
	{
		private var _name:String;
		private var _headIcon:String;
		public function UserNav($name:String,$headIcon:String)
		{
			super();
			_name=$name;
			_headIcon=$headIcon;
		}
		
		override public function onAwake():void
		{
			// TODO Auto Generated method stub
			super.onAwake();
			vbg.y=-vbg.height;
			vbg.alpha=0;
			btn_user.on(Event.CLICK,this,onUserClick);
			btn_xinxi.on(Event.CLICK,this,onShowXinxi);
			addLine();
			addLable("退出实验","comp/btn_boxbg3.png","btnExit");
			var btnExit:Button=vbox.getChildByName("btnExit") as Button;
			btnExit.clickHandler=Handler.create(this,loginOut);
			btn_user.label=_name;
			Api.GetFileBase64(_headIcon,this,function(res){
				var b64:String="data:image/png;base64,"+res.rows.base64str;
				userPhoto.skin=b64;
			})
			
		}
		
		
		private function loginOut():void
		{
			// TODO Auto Generated method stub
			onUserClick();
			//退出实验
			PSteps.exitShiyan();
		}
		
		private function onUserClick():void
		{
			// TODO Auto Generated method stub
			if(vbg.alpha!=0){
				Tween.to(vbg,{y:-vbg.height,alpha:0},400,Ease.circInOut);
			}
			else Tween.to(vbg,{y:btn_user.height+5,alpha:1},400,Ease.circInOut);
		}
		public function addLable($lable:String,$skin:String,$name:String):void{
			var btn:Button=new Button();
			btn.stateNum=3;
			btn.name=$name;
			btn.skin=$skin;
			btn.sizeGrid="4,4,4,33";
			btn.width=btn_xinxi.width;
			btn.height=btn_xinxi.height;
			btn.labelColors="#ffffff,#ffffff,#ffff00";
			btn.labelPadding="0,0,0,5";
			btn.label=$lable;
			btn.labelSize=20;
			vbox.addChild(btn);
			addLine();
			vbg.height=Math.ceil(vbox.numChildren/2)*(btn_xinxi.height+1)+10;
		}
		
		private function addLine():void
		{
			// TODO Auto Generated method stub
			var line:Box=new Box();
			line.graphics.drawLine(0,0,btn_xinxi.width,0,"#ffffff",1);
			vbox.size(btn_xinxi.width,1);
			vbox.addChild(line);
		}
		private function onShowXinxi():void
		{
			// TODO Auto Generated method stub
			onUserClick();
			Browser.window.location.href=Data.httpurl_info;
			//信息页面
//			Browser.window.location.href=Data.HttpURL+"/Student/home/message";
//			if (Data.urlType=="1") 
//			{
//				Browser.window.location.href=Data.HttpURL+"/Student/home/message";
//			}
//			else if (Data.urlType=="2") 
//			{
//				Browser.window.location.href=Data.HttpURL+"/Teacher/home/message";
//			}
//			else if(Data.urlType=="3"){
//				Browser.window.location.href=Data.WapURL+"/Student/home/message";
//			}
//			else if(Data.urlType=="4"){
//				Browser.window.location.href=Data.WapURL+"/Teacher/home/message";
//			}
		}
		
		
		
	}
}